//
//  LoginViewController.m
//  VTravel
//
//  Created by lanouhn on 16/8/1.
//  Copyright © 2016年 xiaoYu. All rights reserved.
//

#import "LoginViewController.h"
#import "RegisterViewController.h"
#import "ForgetPassWordViewController.h"

@interface LoginViewController ()

/** 布尔值判断明文按钮是否点击 */
@property (nonatomic, assign) BOOL isSelected;
/** 自定义导航栏的视图 */
@property (nonatomic, strong) UIView *navigationView;

@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    [self creatClearNavigationBar];
    
    self.title = @"登录";
    
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"登录注册返回键"] style:(UIBarButtonItemStyleDone) target:self action:@selector(handleBackAction)] ;
    self.navigationItem.leftBarButtonItem = leftItem;
    
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithTitle:@"注册" style:UIBarButtonItemStylePlain target:self action:@selector(handleRegister)];
    self.navigationItem.rightBarButtonItem = rightItem;
    
    [self creatUserNameTextField];
    [self creatPassWordTextField];
    
}
#pragma mark - 配置透明导航栏
- (void)creatClearNavigationBar{
    // 设置导航栏的样式
    self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
    // 设置透明的背景图
    [self.navigationController.navigationBar setBackgroundImage:[self drawPngImageWithAlpha:0] forBarMetrics:(UIBarMetricsDefault)];
    // 清除导航栏下的黑线
    [self.navigationController.navigationBar setShadowImage:[UIImage new]];
    // 配置导航栏的渲染色
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    // 配置导航栏标题字体的样式
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor]};
}

#pragma mark -  账号输入框配置
- (void)creatUserNameTextField{
    // 账号输入框配置
    UIView *View1 = [[UIView alloc] initWithFrame:CGRectMake(0, 29, kScreenWidth, 1)];
    View1.backgroundColor = [UIColor whiteColor];
    [self.userNameTextField addSubview:View1];
    
    UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 18, 18)];
    imageView1.image = [UIImage imageNamed:@"登录注册手机号"];
    self.userNameTextField.leftView = imageView1;
    self.userNameTextField.leftViewMode = UITextFieldViewModeAlways;
}


#pragma mark - 密码输入框配置
- (void)creatPassWordTextField{
    // 密码输入框配置
    UIView *View2 = [[UIView alloc] initWithFrame:CGRectMake(0, 29, kScreenWidth, 1)];
    View2.backgroundColor = [UIColor whiteColor];
    [self.passWordTextField addSubview:View2];
    
    UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 18, 18)];
    imageView2.image = [UIImage imageNamed:@"登录注册密码"];
    self.passWordTextField.leftView = imageView2;
    self.passWordTextField.leftViewMode = UITextFieldViewModeAlways;
    
    UIButton *button = [UIButton buttonWithType:(UIButtonTypeCustom)];
    button.frame = CGRectMake(0, 0, 20, 15);
    [button setBackgroundImage:[UIImage imageNamed:@"登录注册非明文密码"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(handleMingWenButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
    self.isSelected = NO;
    self.passWordTextField.secureTextEntry = YES;
    self.passWordTextField.rightView = button;
    self.passWordTextField.rightViewMode = UITextFieldViewModeAlways;
}

#pragma mark - 点击返回按钮的事件
- (void)handleBackAction{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - 注册按钮点击事件 */
- (void)handleRegister{
    kMyLog(@"注册");
    RegisterViewController *registerVC = [[RegisterViewController alloc] init];
    [self.navigationController pushViewController:registerVC animated:YES];
}

#pragma mark - 明文按钮点击事件
- (void)handleMingWenButtonAction:(UIButton *)sender{
    if (self.isSelected == YES) {
        [sender setBackgroundImage:[UIImage imageNamed:@"登录注册非明文密码"] forState:(UIControlStateNormal)];
        self.passWordTextField.secureTextEntry = YES;
        self.isSelected = NO;
    }else{
        [sender setBackgroundImage:[UIImage imageNamed:@"登录注册明文密码"] forState:(UIControlStateNormal)];
        self.passWordTextField.secureTextEntry = NO;
        self.isSelected = YES;
    }
}

#pragma mark - 点击登录按钮事件
- (IBAction)loginAction:(UIButton *)sender {
    
    kMyLog(@"登录");
}
#pragma mark - 忘记密码点击事件
- (IBAction)forgetPassWordAction:(UIButton *)sender {
    
    kMyLog(@"忘记密码");
    
    ForgetPassWordViewController *forgetVC = [[ForgetPassWordViewController alloc] init];
    [self.navigationController pushViewController:forgetVC animated:YES];
    
}


#pragma mark - 点击微信登录页面
- (IBAction)weiChatLoginAction:(UIButton *)sender {
    
    kMyLog(@"微信登录");
}


#pragma mark - 点击QQ登录页面
- (IBAction)QQLoginAction:(UIButton *)sender {
    
    kMyLog(@"QQ登录");
}

#pragma mark - 视图将要出现
- (void)viewWillAppear:(BOOL)animated{
    self.navigationView.hidden = NO;
}
#pragma mark - 视图将要消失
- (void)viewWillDisappear:(BOOL)animated{
    self.navigationView.hidden = YES;
}














/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
